package com.sfh.cpc.mass.model;

import com.sfh.cpc.com.entity.EMass;
import com.sfh.cpc.com.entity.RspBase;
import com.sfh.cpc.com.req.ReqMassQuery;
import com.sfh.cpc.com.req.ReqMassUpdate;
import com.sfh.lib.exception.HandleException;
import com.sfh.lib.rx.IResult;
import com.sfh.lib.rx.IResultSuccess;

/**
 * 功能描述: TODO
 *
 * @author SunFeihu 孙飞虎
 * @date 2018/8/27
 */
public class MassEditModel extends MassAddModel {

    public void getMass(long massId) {
        this.execute(true, new ReqMassQuery(massId), new IResult<RspBase<EMass>>() {
            @Override
            public void onSuccess(RspBase<EMass> data) throws Exception {
                if (data.success()) {

                    setValue("onMassInfo", data.getData());
                } else {
                    showToast(data.getMsg());
                }

            }

            @Override
            public void onFail(HandleException e) {
                showToast(e.getMsg());
            }
        });
    }

    /***
     * 新增
     * @param massAdd
     */
    public void saveMass(ReqMassUpdate massAdd) {
        if (massAdd.chechParams(this)) {
            return;
        }
        this.execute(false,massAdd, new IResultSuccess<RspBase>() {
            @Override
            public void onSuccess(RspBase data) throws Exception {
                if (data.success()) {

                    setValue("onSaveMassSuccess");
                } else {
                    showToast(data.getMsg());
                }
            }
        });
    }
}
